-
Notifications
You must be signed in to change notification settings - Fork 0
feat(frontend): wine lists in the interface (#72) #91
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally as demo: npm run check passes. Hearts and bookmarks on the cards change at once and match the buttons on the wine page, «Har prøvd» takes the wine off «Vil prøve», the list is the same in a private window, and a visitor pressing a heart goes to /konto and comes back to the same page after logging in. I did not try the import of an old list.
Nicely done, and thanks for answering the questions from #65 and #71. Reading the button state from the same cache object with useFragment is a clean way to keep every heart in agreement, and only forgetting the old list once everything is handled is the right call.
One thing to get right on the VM: the description says the frontend is all that is needed, since «the backend from #71 is enough». But the VM does not run #71 yet: its API answers Cannot query field "myLists" right now. Since myLists is in every wine query, publishing the frontend first would break the landing page and the search. The backend has to be updated and migrated first, as you wrote in #81.
Small notes, none blocking:
pending is per button, so two different buttons for the same list (a card heart and «Favoritt» on the wine page) can still send at the same time. Unlikely in practice.
The list rules now live in both lib/wineLists.ts and the backend. They are tested and commented, but have to change together.
The old browser list is imported into whoever logs in, so on a shared computer it could be someone else’s. It only covers data from before this version, so not worth much more than a note.
Good catch regarding the vm, have deploy again in the right order, currently working as it should. Will look into the other notes while working on #73 . |
Closes #72. Continuation of #65 and #71.
What
Users can put wines on their lists from the wine cards and the wine page. The lists are stored on the user, so they follow the user between browsers, and the buttons change at once without a reload. Also fixes the frontend review comments on #65, and answers the questions on #71.
useWineList(wineId, list): returns{ isSaved, toggle, error }. ReadsmyListsfrom the Apollo cache (useFragment), so every button for the same wine agrees. The change shows at once (optimisticResponse, with the same rules as the API inlib/wineLists.ts), and goes back with a Norwegian message if saving fails.myListsin the wine queries (search, landing page, wine page, lists): no extra request per page. The backend batches it with a DataLoader.aria-pressed) with visible text, in a named group./kontoand back to the same page after logging in.me.wines), 24 per page with «Last inn flere», behindRequireAuth. A wine taken off the list disappears at once; the live region says so and focus moves to the list heading.User.wineskeeps one list per name, with pages merged.updateListPagestakes a wine out of the lists it left at once, and drops a list it joined, so it is fetched again with the new wine first.kk:wishlist) moves to the user, oldest first. Wines that no longer exist are skipped. The old list is removed only when every wine has been handled, so a failed connection tries again at the next login.useWishlist,useWishlistWines,wishlistQuery).Review comments from #65 (frontend)
lib/apollo.tsfetchesmeagain when any request answersUNAUTHENTICATED, so the header, the review form and the list buttons all show that the user is logged out.writeQuerybeforeresetStore()was useless, as the review said, sinceresetStore()empties the cache right after. It is gone.resetStore()fetchesmeagain with the new cookie, so the server decides who is logged in. NotclearStore()followed bywriteQuery: in Apollo 4,clearStore()also discards the cache watches (discardWatches: true), so the header would not see the new user.setWorking(false)is infinally. IfonSubmitthrows, the form shows «Noe uventet gikk galt» instead of staying at «Logger inn …».Questions on #71
lists-api.db.test.ts.npm run db:seed:demoinbackend/puts it back as it was.DATABASE_URL=... npm run db:migrateonly works in bash and Git Bash.Commits
fix(frontend): refetch the user when the session ends, and review fixes from Tie reviews to user accounts #65feat(frontend):useWineListagainst the API, withmyListsin the wine queriesfeat(frontend): favourite, «Vil prøve» and «Har prøvd» buttons on the wine pagefeat(frontend): list buttons on the wine cards, and «Vil prøve» from the API on «Mine anmeldelser»feat(frontend): move a «Vil prøve» list from before login to the user, oncetest(e2e): wine lists, login on the way, and the move of an old listdocs: wine lists in the interface, and manual tests for themdocs: answers to the review of Wine lists in the backend (favourites, want to try, tried) #71Tests
lib/wineLists.test.ts: the list rules, the same as the API's.features/lists/useWineList.test.tsx: reads the cache, changes at once, «Har prøvd» takes the wine off «Vil prøve», goes back with a message on failure, updates the list pages, and sends a visitor to log in.features/lists/components/WineListButtons.test.tsxandcomponents/ui/WineCard.test.tsx: names, pressed state, keyboard (Tab, Space, Enter), several cards for the same wine, visitors, and axe.features/my/MyPage.test.tsx: the list from the API, removal with focus and live region, «Last inn flere» with focus, errors, and axe.features/lists/api/listCache.test.tsandlib/apollo.test.ts: the cache rules for the lists, the session link, andUser.wines.features/lists/legacyWishlist.test.tsanduseLegacyWishlistImport.test.tsx: the import order, skipped wines, a failed connection, once only, and nothing for visitors.features/auth/components/AuthForm.test.tsx: the form recovers when sending throws.e2e/lists.spec.ts(desktop and mobile), against a fake API that remembers the lists: keyboard on a card bookmark, the list after a new page load, removal on «Mine anmeldelser», «Har prøvd» on the wine page, a visitor logging in on the way, the move of an old list, and axe on «Mine anmeldelser».backend/src/lists/lists-api.db.test.ts: a tried wine can go back on «Vil prøve».Test helpers:
meMock,TEST_USERandAuthReadyinsrc/test/.renderWithRouternow includes Apollo andAuthProvider, like the app, since the wine cards need to know who is logged in.Also tested by hand, following docs/manual-testing.md sections 2, 5 and 6.
Updated test counts for frontend and e2e in README.md
How to review
npm run db:seed:demo, and log in asdemo/kork-og-krone./konto, and back after logging in.localStorage.setItem('kk:wishlist', JSON.stringify(['<id>', '<id>']))in the console, then log in and open «Mine anmeldelser».After merge (VM)
No new migrations: the backend from #71 is enough. Build the frontend again:
cd frontend npm ci npm run buildvmIf the demo user has been changed, run
npm run db:seed:demoinbackend/.Not in this PR